package com.ruoyi.comn.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.comn.domain.ComnDeptGroup;
import com.ruoyi.comn.service.IComnDeptGroupService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 部门分组Controller
 * 
 * @author ruoyi
 * @date 2021-11-30
 */
@RestController
@RequestMapping("/deptGroup")
public class ComnDeptGroupController extends BaseController
{
    @Autowired
    private IComnDeptGroupService comnDeptGroupService;

    /**
     * 查询部门分组列表
     */
    @PreAuthorize(hasPermi = "comn:deptGroup:list")
    @GetMapping("/list")
    public TableDataInfo list(ComnDeptGroup comnDeptGroup)
    {
        startPage();
        List<ComnDeptGroup> list = comnDeptGroupService.selectComnDeptGroupList(comnDeptGroup);
        return getDataTable(list);
    }

    /**
     * 导出部门分组列表
     */
    @PreAuthorize(hasPermi = "comn:deptGroup:export")
    @Log(title = "部门分组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ComnDeptGroup comnDeptGroup) throws IOException
    {
        List<ComnDeptGroup> list = comnDeptGroupService.selectComnDeptGroupList(comnDeptGroup);
        ExcelUtil<ComnDeptGroup> util = new ExcelUtil<ComnDeptGroup>(ComnDeptGroup.class);
        util.exportExcel(response, list, "部门分组数据");
    }

    /**
     * 获取部门分组详细信息
     */
    @PreAuthorize(hasPermi = "comn:deptGroup:query")
    @GetMapping(value = "/{deptGroupUuid}")
    public AjaxResult getInfo(@PathVariable("deptGroupUuid") String deptGroupUuid)
    {
        return AjaxResult.success(comnDeptGroupService.selectComnDeptGroupByDeptGroupUuid(deptGroupUuid));
    }

    /**
     * 新增部门分组
     */
    @PreAuthorize(hasPermi = "comn:deptGroup:add")
    @Log(title = "部门分组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ComnDeptGroup comnDeptGroup)
    {
        return toAjax(comnDeptGroupService.insertComnDeptGroup(comnDeptGroup));
    }

    /**
     * 修改部门分组
     */
    @PreAuthorize(hasPermi = "comn:deptGroup:edit")
    @Log(title = "部门分组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ComnDeptGroup comnDeptGroup)
    {
        return toAjax(comnDeptGroupService.updateComnDeptGroup(comnDeptGroup));
    }

    /**
     * 删除部门分组
     */
    @PreAuthorize(hasPermi = "comn:deptGroup:remove")
    @Log(title = "部门分组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deptGroupUuids}")
    public AjaxResult remove(@PathVariable String[] deptGroupUuids)
    {
        return toAjax(comnDeptGroupService.deleteComnDeptGroupByDeptGroupUuids(deptGroupUuids));
    }
}
